#!/bin/bash
date "+%Y-%m-%d %H:%M:%S"
echo "~~~~~~~~~~~~~~~~~~~~备份开始~~~~~~~~~~~~~~~~~~~~~~~~~"

#让sudo命令生效
echo rock | sudo -S ls

mkdir shared

# 目标： //<计算机IP>/<共享文件夹名>    ，说明: / 不能 \
sudo mount -t cifs -o username=rewi,password= //10.162.130.10/share shared

# shellcheck disable=SC2164
cd shared || exit
ls

#把硬盘上的内容全部备份到一个磁盘文件中
sudo dd if=/dev/mmcblk0 of=linuxBackup20230201.img
date "+%Y-%m-%d %H:%M:%S"
echo "~~~~~~~~~~~~~~~~~~~~备份完成~~~~~~~~~~~~~~~~~~~~~~~~~"

#也可以压缩一下：generates xxx.img.xz
sudo xz linuxBackup20230201.img
date "+%Y-%m-%d %H:%M:%S"
echo "~~~~~~~~~~~~~~~~~~~~压缩完成~~~~~~~~~~~~~~~~~~~~~~~~~"

#清除
#cd ..
#sudo umount shared
#sudo rm -rf shared